// echo partial file, should not compile along

using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Collections.Generic;
using HarmonyLib;
using Utils;
namespace GongfaEffect;

public partial class GongfaEffect {
//! 虽然这里只是洗头小妹mod，但我们可以很轻松愉快地借用此处逻辑控制各种过月行为，比如在PeriAdvanceMonth_ExecuteGeneralAction搞一个追着太吾指点武功的行为。
    public static class BingQingYuJie {
//! 首先，请允许我介绍一下partial class这个神器。这个神器允许我们把一个大类拆成很多个小文件。用的时候把文件拼起来就可以了。
//! 这里需要注意一点，写作Config.PersonalNeed.DefKey.MakeLove的这个东西是一个常数，而这个常数随时会被茄子改掉，所以需要用反射，在启动Mod时更新这些常数。
        public static sbyte DefKey_GetRevenge=Config.PersonalNeed.DefKey.GetRevenge;
        public static sbyte DefKey_MakeLove=Config.PersonalNeed.DefKey.MakeLove;
        public static short DefKey_Pregnant=Config.CharacterFeature.DefKey.Pregnant;
        public static short DefKey_DreamLover=Config.CharacterFeature.DefKey.DreamLover;
        public static sbyte AgeGroup_Adult=GameData.Domains.Character.AgeGroup.Adult;
        public static ushort RelationType_Enemy=GameData.Domains.Character.Relation.RelationType.Enemy;
        public static ushort RelationType_Adored=GameData.Domains.Character.Relation.RelationType.Adored;
        public static ushort RelationType_Friend=GameData.Domains.Character.Relation.RelationType.Friend;
        public static short DefKey_FulongServant=Config.CharacterFeature.DefKey.FulongServant;
        public const short Defkey_BingQingYuJIe=257; // 目前这个方法并没有被暴露在defkey之外，因此只能如此使用。
        public static void Patch(RobustHarmonyInstance HarmonyInstance, string ModIdStr){
            DefKey_GetRevenge=(sbyte)typeof(Config.PersonalNeed.DefKey).GetField("GetRevenge",(BindingFlags)(-1)).GetValue(null);
            DefKey_MakeLove=(sbyte)typeof(Config.PersonalNeed.DefKey).GetField("MakeLove",(BindingFlags)(-1)).GetValue(null);
            DefKey_Pregnant=(short)typeof(Config.CharacterFeature.DefKey).GetField("Pregnant",(BindingFlags)(-1)).GetValue(null);
            DefKey_DreamLover=(short)typeof(Config.CharacterFeature.DefKey).GetField("DreamLover",(BindingFlags)(-1)).GetValue(null);
            DefKey_FulongServant=(short)typeof(Config.CharacterFeature.DefKey).GetField("FulongServant").GetValue(null);
            AgeGroup_Adult=(sbyte)typeof(GameData.Domains.Character.AgeGroup).GetField("Adult",(BindingFlags)(-1)).GetValue(null);
            RelationType_Enemy=(ushort)typeof(GameData.Domains.Character.Relation.RelationType).GetField("Enemy",(BindingFlags)(-1)).GetValue(null);
            RelationType_Adored=(ushort)typeof(GameData.Domains.Character.Relation.RelationType).GetField("Adored",(BindingFlags)(-1)).GetValue(null);
            RelationType_Friend=(ushort)typeof(GameData.Domains.Character.Relation.RelationType).GetField("Friend",(BindingFlags)(-1)).GetValue(null);
            //GameData.Domains.DomainManager.Mod.GetSetting(ModIdStr, "beautify", ref xn_beautify);
            HarmonyInstance.PatchAll(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType);
        }
//! 这是另一种注入方式，直接修改IL指令，在合适位置进行注入。好处可能是性能高，但坏处是，这玩意需要会编译（至少需要能看懂IL知道C#是个栈，ld*是消耗0个或者多个参数（ldloc，ldarg不需要消耗参数，但ldfld需要消耗一个，ldelem好像需要消耗两个）之后往栈上推元素，st*是消耗一个或者多个栈上元素修改栈以外的元素的值，知道call，callvirt，newobj等等语句是调用函数）
/*
    [HarmonyPatch(typeof(GameData.Domains.Character.Character),"PeriAdvanceMonth_ExecuteFixedActions")]
        public static IEnumerable<CodeInstruction> Transpiler(MethodBase __originalMethod, IEnumerable<CodeInstruction> instructions) {
            instructions = Transpilers.MethodReplacer(instructions,typeof(GameData.Domains.Character.ParallelModifications.PeriAdvanceMonthFixedActionModification).GetProperty("IsChanged").GetGetMethod(),typeof(BingQingYuJie).GetMethod("InjectIsChanged"));
            return instructions;
        }
        public static IEnumerable<CodeInstruction> Transpiler(MethodBase __originalMethod, IEnumerable<CodeInstruction> instructions) {
            instructions = new CodeMatcher(instructions)
                .MatchForward(false, // false = move at the start of the match, true = move at the end of the match
                    new CodeMatch(OpCodes.Callvirt, typeof(GameData.Domains.Character.ParallelModifications.PeriAdvanceMonthFixedActionModification).GetProperty("IsChanged").GetGetMethod())
                ).Repeat( matcher => // Do the following for each match
                    matcher
                    .Advance(1)
                    .InsertAndAdvance(
                        new CodeInstruction(OpCodes.Ldarg_0),
                        new CodeInstruction(OpCodes.Dup),
                        new CodeInstruction(OpCodes.Ldfld,typeof(GameData.Domains.Character.Character).GetField("_personalNeeds",(BindingFlags)(-1))),
                        new CodeInstruction(OpCodes.Call,typeof(WeaponModifier).GetMethod("InjectIsChanged"))
                    )
                ).InstructionEnumeration();
            return instructions;
        }
        public static bool InjectIsChanged(GameData.Domains.Character.ParallelModifications.PeriAdvanceMonthFixedActionModification mod, GameData.Domains.Character.Character that, List<GameData.Domains.Character.Ai.PersonalNeed> personalNeeds) {
            //var pn=(List<GameData.Domains.Character.Ai.PersonalNeed>)typeof(GameData.Domains.Character.Character).GetField("_personalNeeds").GetValue(mod.Character);
            foreach(GameData.Domains.Character.Ai.PersonalNeed need in personalNeeds){
            }
            return mod.IsChanged;
        }
// */

//! 这里选择Postfix/Prefix来注入，虽然代码因为unsafe不太好看，但至少比IL好看。
//! 让我们首先完成后端(Offline)计算部分的注入
        public static FieldInfo _birthMonth=typeof(GameData.Domains.Character.Character).GetField("_birthMonth",(BindingFlags)(-1));
        public static FieldInfo _cur=typeof(GameData.Domains.Character.Character).GetField("_currMainAttributes",(BindingFlags)(-1));
        public static FieldInfo _bmx=typeof(GameData.Domains.Character.Character).GetField("_baseMainAttributes",(BindingFlags)(-1));
        public static FieldInfo _actualAge=typeof(GameData.Domains.Character.Character).GetField("_actualAge",(BindingFlags)(-1));
        public static FieldInfo _currAge=typeof(GameData.Domains.Character.Character).GetField("_currAge",(BindingFlags)(-1));
        [HarmonyPostfix]
        [HarmonyPatch(typeof(GameData.Domains.Character.Character),"OfflineExecuteFixedAction_MakeLove")]
        public static unsafe void BeginModify(GameData.Domains.Character.Character __instance, Redzen.Random.IRandomSource random, HashSet<int> currBlockCharSet, GameData.Domains.Character.ParallelModifications.PeriAdvanceMonthFixedActionModification mod, List<GameData.Domains.Character.Ai.PersonalNeed> ____personalNeeds, List<short> ____learnedCombatSkills, ref sbyte ____birthMonth, ref short ____actualAge, ref short ____currAge, ref short ____health, GameData.Domains.Character.MainAttributes ____currMainAttributes, GameData.Domains.Character.MainAttributes ____baseMainAttributes) {
//! 如你所见，上面那一坨变量用到了三下划线读当前instance的私有变量的神奇算法，____health实际上就是this._health
//! 应当注意的是，对结构体或者内置变量，C#的参数传递是值传递，而非引用传递，你对值的修改不会影响真实数据的状态。
//! 基本上可以这么理解：我有5个苹果，传class的时候我会告诉你我在哪里放了苹果，但不告诉你苹果有几个，这时候你拿走苹果，我的苹果就真的少了
//! 而传struct或者内置类型的时候，我告诉你的是，我有5个苹果，不劳烦您点数了——这时候你把5改成4，并不会减少我手中苹果的数量。

//! 这里是一个判断，看看人物的Defkey_BingQingYuJIe功法（冰清玉洁）是否逆练
            GameData.Domains.CombatSkill.CombatSkill cs;
            if(GameData.Domains.DomainManager.CombatSkill.TryGetElement_CombatSkills(new GameData.Domains.CombatSkill.CombatSkillKey(__instance.GetId(), Defkey_BingQingYuJIe),out cs) && cs.GetDirection() == GameData.Domains.CombatSkill.CombatSkillDirection.Reverse && __instance.GetAgeGroup()>=AgeGroup_Adult){
                // TODO
                // this._extraNeili 可以用来修改内力获取/丧失，也可以使用GetPureMaxNeili的相关逻辑修改功法内力完成魅魔逻辑
                int dissatisfaction=5;
                if(mod.MakeLoveTargetList==null){
                    mod.MakeLoveTargetList=new List<(GameData.Domains.Character.Character target, GameData.Domains.Character.ParallelModifications.PeriAdvanceMonthFixedActionModification.MakeLoveState makeLoveState, bool isPregnant)>();
                    var id=__instance.GetId();
                    foreach (int charId in currBlockCharSet)if(charId!=id) {
                        var victim=GameData.Domains.DomainManager.Character.GetElement_Objects(charId);
                        if(victim.GetGender()!=0 && !victim.GetFeatureIds().Contains(DefKey_FulongServant)){
                            dissatisfaction-=2;
//! 这里做了一次机智的传参，使用游戏中不存在的数据（RapeFail但有了孩子）进行标记，如此标记不需要大刀阔斧地修改游戏逻辑，但需要在游戏真正用到数据之前把数据改成正常的样子。
                            mod.MakeLoveTargetList.Add((victim, GameData.Domains.Character.ParallelModifications.PeriAdvanceMonthFixedActionModification.MakeLoveState.RapeFail, __instance.GetGender()==0));
//! 需要注意的是……男子汉大丈夫好像也是可以搞在一起的，由于后面只会拦截女性RapeFail，把男性RapeFail放到后面会导致游戏坏档。
                        } else {
                            dissatisfaction+=1;
                            if(GameData.Domains.DomainManager.CombatSkill.TryGetElement_CombatSkills(new GameData.Domains.CombatSkill.CombatSkillKey(__instance.GetId(), Defkey_BingQingYuJIe),out cs) && cs.GetDirection() == GameData.Domains.CombatSkill.CombatSkillDirection.Direct){
                                var need=GameData.Domains.Character.Ai.PersonalNeed.CreatePersonalNeed(DefKey_GetRevenge,victim.GetId());
                                need.RemainingMonths=12;
                                ____personalNeeds.Add(need);
                            }
                        }
                    }
                    if(mod.MakeLoveTargetList.Count==0){
//! 使用下面三行语句简单粗暴地获取关系网
                        var potentials=new HashSet<int>();
                        var x=GameData.Domains.DomainManager.Character.GetRelatedCharacters(id);
                        if(x!=null)x.GetAllRelatedCharIds(potentials,true);

                        short y=-32768;
                        int c=0;
                        foreach(int charId in potentials){
                            if(GameData.Domains.DomainManager.Character.IsCharacterAlive(charId)){
                                var victim=GameData.Domains.DomainManager.Character.GetElement_Objects(charId);
                                if(victim.GetGender()==1){
                                    var z=GameData.Domains.DomainManager.Character.GetFavorability(id,charId);
                                    if(y<z){
                                        y=z;
                                        c=charId;
                                    }
                                }
                                if(y!=-32768){
                                    var need=GameData.Domains.Character.Ai.PersonalNeed.CreatePersonalNeed(DefKey_MakeLove,c);
                                    need.RemainingMonths=12;
                                    ____personalNeeds.Add(need);
                                } else {
                                    dissatisfaction+=5;
                                }
                            }
                        }
                    }
                }

                if(dissatisfaction<0)dissatisfaction=0;
                if(__instance.GetGender()==1){
//                    if(!__instance.GetFeatureIds().Contains(DefKey_DreamLover))
//! 在这里可以考虑给太吾后代一点优待，但考虑到，这个优待并不会对太吾生效，所以加不加这个东西其实无所谓。
                    for (int i = 0; i < 6; i++) {
//! 这里没什么好说的，__一样的指针操作，这是使用结构体的必然代价。
                        var curr=*(____currMainAttributes.Items+i);
                        var bmax=*(____baseMainAttributes.Items+i);

                        var count=(bmax-(curr-11))/11;

                        *(____baseMainAttributes.Items+i)-=(short)count;
                        *(____currMainAttributes.Items+i)+=(short)(count*10);

                        if(*(____currMainAttributes.Items+i)>*(____baseMainAttributes.Items+i)){
                            *(____baseMainAttributes.Items+i)-=1;
                            *(____currMainAttributes.Items+i)+=10;
                        }

                        if(*(____baseMainAttributes.Items+i)<1){
                            *(____baseMainAttributes.Items+i)=1;
                        }
                        if(*(____currMainAttributes.Items+i)<0){
                            *(____currMainAttributes.Items+i)=0;
                        }
                    }
                    return;
                }
//! 到这里我们纯化了习练逆冰清玉洁的福利姬，下面可以开始过月逻辑操作了
                {
                    var lst=new List<int>();
                    for (int i = ____personalNeeds.Count - 1; i >= 0; i--) {
//! 虽然dump数据的我们发现了23是春宵，但以防万一，使用DefKey_MakeLove会使Mod更稳妥一些
                        if (____personalNeeds[i].TemplateId ==  DefKey_MakeLove) {
                            lst.Add(i);
                        }
                    }

                    foreach (int charId in currBlockCharSet){
                        GameData.Domains.Character.Character victim;
                        // 这里可以从龙岛请来的老公排除在外，毕竟龙岛忠仆嘛……
                        if(GameData.Domains.DomainManager.Character.TryGetElement_Objects(charId, out victim) && victim.GetGender()==1 && !victim.GetFeatureIds().Contains(DefKey_FulongServant)){
                            if (lst.Count==0)break;
                            var nr=random.Next(lst.Count);
//! 需注意，这里是结构体操作，我们复制了一个结构体x，将x自减，然后存回去
//! 这里不能换成____personalNeeds[lst[nr]].RemainingMonths-=1，因为你拿到的____personalNeeds[lst[nr]]是一个新结构体
                            var x=____personalNeeds[lst[nr]];
                            x.RemainingMonths-=1;
                            if(x.RemainingMonths==0){
                                GameData.Utilities.CollectionUtils.SwapAndRemove(lst,nr);
                            } else {
                                ____personalNeeds[lst[nr]]=x;
                            }
                        }
                    }
                    for (int i = ____personalNeeds.Count - 1; i >= 0; i--) {
                        if (____personalNeeds[i].TemplateId == DefKey_MakeLove){
                            if(____personalNeeds[i].RemainingMonths==0) {
                                GameData.Utilities.CollectionUtils.SwapAndRemove(____personalNeeds,i);
                            } else {
                                dissatisfaction+=____personalNeeds[i].RemainingMonths;
                            }
                        }
                    }
                }
//! 开始执行愉快的反射操作
//! 由于这些东西是固定值，我们可以只计算一次，而不必每次执行函数都来一遍GetField
//        public static MethodInfo _birthMonth=typeof(GameData.Domains.Character.Character).GetField("_birthMonth",(BindingFlags)(-1));
//        public static MethodInfo _cur=typeof(GameData.Domains.Character.Character).GetField("_currMainAttributes",(BindingFlags)(-1));
//        public static MethodInfo _bmx=typeof(GameData.Domains.Character.Character).GetField("_baseMainAttributes",(BindingFlags)(-1));
//        public static MethodInfo _actualAge=typeof(GameData.Domains.Character.Character).GetField("_actualAge",(BindingFlags)(-1));
//        public static MethodInfo _currAge=typeof(GameData.Domains.Character.Character).GetField("_currAge",(BindingFlags)(-1));
                var month=GameData.Domains.DomainManager.World.GetCurrMonthInYear();
                foreach(var m in mod.MakeLoveTargetList){
//                    if(m.Item1.GetFeatureIds().Contains(DefKey_DreamLover))continue;//可以优待一下太吾后代，但想了想，其实没什么必要的
                    //CaiYang(m.Item1,mod);
                    {
                        var victim=m.Item1;
                        if(victim.GetGender()==0){
                            continue;
                        }
                        var curr=(sbyte)_birthMonth.GetValue(victim);
                        if(curr+10<=month || curr-2 <= month && curr>month){
                            _actualAge.SetValue(victim,(short)(1+victim.GetActualAge()));
                            _currAge.SetValue(victim,(short)(1+victim.GetCurrAge()));
                        }
                        _birthMonth.SetValue(victim,(sbyte)((curr+10)%(sbyte)12));
//! 应注意，这里仍然是新结构体，无论你写的是不是反射。
//                        var cur=(GameData.Domains.Character.MainAttributes)_cur.GetValue(victim);
//                        var bmx=(GameData.Domains.Character.MainAttributes)_bmx.GetValue(victim);
                        var cur=victim.GetCurrMainAttributes();
                        var bmx=victim.GetBaseMainAttributes();
                        for (int i = 0; i < 6; i++) {
                            if(*(cur.Items+i)+5<*(bmx.Items+i)){
                                *(bmx.Items+i)-=1;
                                *(cur.Items+i)+=5;
                            } else {
                                *(cur.Items+i)-=5;
                            }
                        }
//! 将修改后的结构体写回
//! 我讨厌结构体。
                        _cur.SetValue(victim,cur);
                        _bmx.SetValue(victim,bmx);
                    }
                    //BuYin(__instance,mod);
                    {
                        if(____birthMonth== month){
                            if(____currAge>16){
                                ____currAge-=1;
                                ____actualAge-=1;
                            } else {
//! 这里需要注意，如果年龄被减到小于16岁，会出现不少BUG
//! 一个是立绘不会及时更新，这可能导致天山童佬的诞生……
                                ____birthMonth+=11;
                            }
                            //mod.ActualAgeChanged = true;
                        }
                        ____birthMonth+=1;
                        ____birthMonth%=12;
                        dissatisfaction-=1;
                        //if (____currAge<16){
                            //if ((int)____currAge >= GlobalConfig.Instance.AgeBaby){
                        //        mod.NewClothingTemplateId = 65;
                            //} else {
                        //        mod.NewClothingTemplateId = -1;
                            //}
                        //}//mod.NewClothingTemplateId=__instance.TryGetNewClothingWhenAgeGroupChanges(context.Random, 0);
                    }
                }
//! 在这里可以进行一个BUG的de-……
//                var nm=__instance.GetFullName().GetName(__instance.GetGender(),GameData.Domains.DomainManager.World.GetCustomTexts());
//                GameData.Utilities.AdaptableLog.Info(nm.Item1+nm.Item2+"("+__instance.GetId().ToString()+")"+(*____currMainAttributes.Items).ToString()+"/"+(*____baseMainAttributes.Items).ToString());
                for (int i = 0; i < 6; i++) {
                    short dec=(short)dissatisfaction;

                    var curr=*(____currMainAttributes.Items+i);
                    var bmax=*(____baseMainAttributes.Items+i);

                    var count=(bmax-(curr-dissatisfaction))/11;

                    *(____baseMainAttributes.Items+i)-=(short)count;
                    *(____currMainAttributes.Items+i)+=(short)(count*10);

                    if(*(____currMainAttributes.Items+i)>*(____baseMainAttributes.Items+i)){
                        *(____baseMainAttributes.Items+i)+=1;
                        *(____currMainAttributes.Items+i)-=10;
                    }
                    if(*(____baseMainAttributes.Items+i)<1){
                        *(____baseMainAttributes.Items+i)=1;
                    }
                    if(*(____currMainAttributes.Items+i)<0){
                        *(____currMainAttributes.Items+i)=0;
                    }
                }
//                GameData.Utilities.AdaptableLog.Info(nm.Item1+nm.Item2+"("+__instance.GetId().ToString()+") "+(*____currMainAttributes.Items).ToString()+"/"+(*____baseMainAttributes.Items).ToString());

                // 需要更新ChangeBaseMainAttribute
            }
        }
//! 这里是前端……emm……后端的单线程前端
        [HarmonyPrefix]
        [HarmonyPatch(typeof(GameData.Domains.Character.Character),"ComplementPeriAdvanceMonth_ExecuteFixedActions")]
        public static unsafe void CompleteModify(GameData.Common.DataContext context, GameData.Domains.Character.ParallelModifications.PeriAdvanceMonthFixedActionModification mod){
//! 为了保证性能，这里必须尽早把一些没用的东西筛出去
            if(mod.MakeLoveTargetList == null) return;
            GameData.Domains.Character.Character character = mod.Character;
//!        某个车祸现场的debug
//            GameData.Utilities.AdaptableLog.Info("("+character.GetId().ToString()+") MakeLove");
//            if(character.GetId()==6219 || character.GetId()==6207 ){ // debug!
//                foreach(var m in mod.MakeLoveTargetList){
//                    GameData.Utilities.AdaptableLog.Info(m.Item1.GetId().ToString()+" "+m.Item2.ToString()+m.Item3);
//                }
//            }
            GameData.Domains.CombatSkill.CombatSkill cs;
            if(GameData.Domains.DomainManager.CombatSkill.TryGetElement_CombatSkills(new GameData.Domains.CombatSkill.CombatSkillKey(character.GetId(), Defkey_BingQingYuJIe),out cs) && cs.GetDirection() == GameData.Domains.CombatSkill.CombatSkillDirection.Reverse){
                if(character.GetGender()!=0){
//! 我完全不懂序列化与反序列化，不过螺舟代码里面到处都有，这就足够了。
                    character.SetBaseMainAttributes(character.GetBaseMainAttributes(),context);
                    character.SetCurrMainAttributes(character.GetCurrMainAttributes(),context);
                    return;
                }
//! 到这里，仍然是只剩下福利姬的状态
//! 在开始一切之前，让我们先给福利姬美容一下
//! 美容函数在下面，大家可以自行调用
                bool  changed=character.beautify(context);
                // if(changed)character.SetAvatar(character.GetAvatar(), context); // 需要通知前端更新人物形象
//! 之后我们就可以愉快地执行其他逻辑了。
                GameData.Domains.LifeRecord.LifeRecordCollection lifeRecordCollection = GameData.Domains.DomainManager.LifeRecord.GetLifeRecordCollection();
//! 未来想修改过月提醒的话，可以把这一项加上去
                //GameData.Domains.World.Notification.MonthlyNotificationCollection monthlyNotificationCollection = GameData.Domains.DomainManager.World.GetMonthlyNotificationCollection();
//! 秘闻大概可以不加……
                //GameData.Domains.Information.Collection.SecretInformationCollection secretInformationCollection = GameData.Domains.DomainManager.Information.GetSecretInformationCollection();
                int currDate = GameData.Domains.DomainManager.World.GetCurrDate();
                GameData.Domains.Map.Location location = character.GetLocation();
                int taiwuCharId = GameData.Domains.DomainManager.Taiwu.GetTaiwuCharId();
//! 下面这行注释就是血案发生的侦破过程
                ////////debug only//mod.MakeLoveTargetList[0]=(mod.MakeLoveTargetList[0].Item1, mod.MakeLoveTargetList[0].Item2, false);
                for(int i=0;i<mod.MakeLoveTargetList.Count;i++) {
                    if(changed)character.beautify(context); // 为了（作死）节约计算量，这里如果未发现changed，说明医美已经完成，不需要进一步修改容貌，故不应继续执行函数。
                    var victim=mod.MakeLoveTargetList[i].Item1;
                    if(mod.MakeLoveTargetList[i].Item2==GameData.Domains.Character.ParallelModifications.PeriAdvanceMonthFixedActionModification.MakeLoveState.RapeFail && mod.MakeLoveTargetList[i].Item3){
//! 这里是结构体血案的案发现场
                        //mod.MakeLoveTargetList[i].Item3=false;
                        //mod.MakeLoveTargetList[i].Item2=GameData.Domains.Character.ParallelModifications.PeriAdvanceMonthFixedActionModification.MakeLoveState.Illegal
                        mod.MakeLoveTargetList[i]=(mod.MakeLoveTargetList[i].Item1, GameData.Domains.Character.ParallelModifications.PeriAdvanceMonthFixedActionModification.MakeLoveState.Illegal, false);
//! 如你所见，我们交换了被害者与运功人的位置……现在被害人会对运功者爱慕，而运功者与被害人为仇敌关系
                        GameData.Domains.DomainManager.Character.AddRelation(context, character.GetId(), victim.GetId(),  RelationType_Enemy , currDate);
                        GameData.Domains.DomainManager.Character.AddRelation(context, victim.GetId(), character.GetId(),  RelationType_Adored , currDate);
                        GameData.Domains.DomainManager.Character.ChangeRelationType(context, character.GetId(), victim.GetId(),  RelationType_Adored, RelationType_Enemy);
                        GameData.Domains.DomainManager.Character.ChangeRelationType(context, victim.GetId(), character.GetId(),  RelationType_Enemy, RelationType_Adored);
                        //GameData.Domains.DomainManager.Character.AddRelation(context, victim.GetId(), character.GetId(),  RelationType_Friend , currDate); // Friend是双向关系，这里就不写了
                        GameData.Domains.DomainManager.Character.ChangeFavorability(context, victim, character, 4000);
                    }
//! 让我们继续愉快地执行序列化与反序列化的指令
                    victim.SetBaseMainAttributes(victim.GetBaseMainAttributes(),context);
                    victim.SetCurrMainAttributes(victim.GetCurrMainAttributes(),context);
                    victim.SetActualAge(victim.GetActualAge(), context);
//! 最后加一行洗头妹描述，完美。
                    lifeRecordCollection.AddBarbSucceed(character.GetId(), currDate, victim.GetId(), location);
                }
                character.SetBaseMainAttributes(character.GetBaseMainAttributes(),context);
                character.SetCurrMainAttributes(character.GetCurrMainAttributes(),context);
                character.SetActualAge(character.GetActualAge(), context);
                if(changed)character.SetAvatar(character.GetAvatar(), context); // 需要通知前端更新人物形象
//! 在这里我们又可以进行一个bug的de-……
//                var nm=character.GetFullName().GetName(character.GetGender(),GameData.Domains.DomainManager.World.GetCustomTexts());
//                var y=character.GetBaseMainAttributes();
//                GameData.Domains.Character.PregnantState garbage;
//                GameData.Utilities.AdaptableLog.Info(nm.Item1+nm.Item2+"("+character.GetId().ToString()+") at "+location.ToString()+", curr "+(*y.Items).ToString()+" -- 怀:"+GameData.Domains.DomainManager.Character.TryGetPregnantState(character.GetId(), out garbage)+"甲:"+character.GetFeatureIds().Contains(DefKey_Pregnant));
            }
        }
    }
}
